#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;

class User
{
public:
    User(const string &name)
        : _name(name)
          , _score(0)
    {
    }
    void consume(float delta)
    {
        _score += delta;
        cout << ">> " << _name << " consume " << delta << endl;
    }
protected:
    string _name;
    float _score;
};

class VipUser
: public User
{
public:
    VipUser(const string &name)
        : User(name)
          , _discount(1)
    {
    }
    void consume2(float delta)
    {
        float realDelta = delta * _discount;
        _score += realDelta;
        updateDiscount();
        cout << ">> " << _name << " consume " << realDelta << endl;
    }
    void updateDiscount()
    {
        if(_score > 10000)
        {
            _discount = 0.7;
        }
        else if(_score > 5000)
        {
            _discount = 0.8;
        }
        else if(_score > 1000)
        {
            _discount = 0.9;
        }
        else
        {
            _discount = 1;
        }
    }
private:
    float _discount;
};



void test0(){
    User user("lili");
    user.consume(2000);
    user.consume(2000);
    cout << endl;
    VipUser vip("lucy");
    vip.consume2(2000);
    vip.consume2(2000);//添加自己的个性
    vip.consume(2000);//基类的方法还是保留在,
}

int main(int argc, char * argv[])
{
    test0();
    return 0;
}


